package leetcode.hot100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

public class number47 {
    static HashSet<List<Integer>>set=new HashSet<>();
    static ArrayList<List<Integer>>arrayList=new ArrayList<>();
    public static void main(String[] args) {
        List<List<Integer>> lists = permuteUnique(new int[]{1, 1, 2});
        lists.forEach(s->{
            System.out.println(s);
        });
        System.out.println();
        for (List<Integer> integers : arrayList) {
            System.out.println(integers);
        }
    }
    public static List<List<Integer>> permuteUnique(int[] nums) {
        dfs(nums,0);
        return new ArrayList<>(set);
    }
    public static void dfs(int []nums,int i){
        if(i==nums.length-1){
            set.add(Arrays.stream(nums).boxed().collect(Collectors.toList()));
            arrayList.add(Arrays.stream(nums).boxed().collect(Collectors.toList()));
        }
        for(int j=i;j<nums.length;j++){
            swap(nums,i,j);
            dfs(nums,i+1);
            swap(nums,i,j);
        }
    }
    public static void swap(int[]arr,int i,int j){
        int t=arr[i];
        arr[i]=arr[j];
        arr[j]=t;
    }
}
